import * as actionTypes from './constants';
import { fromJS } from 'immutable';

const defaultStatus = fromJS({
  focused: false,
  mouseIn: false,
  list: [],
  page: 1,
  totalPage: 1,
});

const reducer = (state = defaultStatus, action) => {
  switch (action.type) {
    case actionTypes.SERACH_FOCUSE:
      return state.set('focused', true);
    case actionTypes.SERACH_BLUR:
      return state.set('focused', false);
    case actionTypes.SET_LIST:
      return state.set('list', action.list).set('totalPage', action.totalPage);
    case actionTypes.HANDLE_CHANGE:
      return state.set('page', action.page);
    case actionTypes.MOUSE_ENTER:
      return state.set('mouseIn', true);
    case actionTypes.MOUSE_LEAVE:
      return state.set('mouseIn', false);
    default:
      return state;
  }
};
export default reducer;
